<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>Global Functions | Raxan User Guide</title>
    <link href="../raxan/styles/master.css" rel="stylesheet" type="text/css" />
    <!--[if IE]><link rel="stylesheet" href="../raxan/styles/master.ie.css" type="text/css"><![endif]-->
    <link href="style.css" rel="stylesheet" type="text/css" />
    <link href="highlight/styles/default.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="highlight/highlight.js"></script>
    <script type="text/javascript">
        hljs.initHighlightingOnLoad('javascript','html','php');
    </script>

</head>

<body>
    <div class="container c48 prepend-top">
        <h2 class="bottom">Raxan User Guide</h2>
        <div class="navbar">
            <div class="lf"><div class="rt"><div class="md">
                <ul>
                    <li><a href="../index.html" title="The Rich Ajax, CSS &amp; PHP Framework" >Home</a></li>
                    <li><a href="table-of-contents.html" title="Blog Posts" >Table Of Contents</a></li>
                    <li><a href="../php-examples/index.php" title="PHP Examples" >PHP Examples</a></li>
                    <li><a href="../css-examples/index.html" title="User Guide" >CSS Examples</a></li>
                </ul>
            </div></div></div>
        </div>
        <div class="prepend1 append1">
            <div class="ltm" align="right">
                <a href="table-of-contents.html" title="Show Table of Content">
                    <img src="images/toc-button.png"  alt="Table of Contents" />
                </a>
            </div>
            <h2>Global Functions</h2>

<p>In addition to extending the RaxanWebPage class, there are four other globally accessible functions that are available to developers. These functions are wrappers or shortcuts to commonly used objects or methods. Calling this method will automatically create an instance of the RaxanWebPage class if a Page Controller was not found.</p>

<p><strong>P()</strong> - This function provides a reference the default page controller, which is normally the first instance of the RaxanWebPage class.</p>

<pre><code>&lt;?php
    P()-&gt;append('Hi there!'); 
?&gt;
</code></pre>

<p><strong>C()</strong> - This provides a reference to the RaxanClientExtension class, which is used to generate and execute client-side action scripts. These action scripts are normally jQuery commands that are executed within the client's browser. Calling this method will automatically create an instance of the RaxanClientExtension class and load the Raxan startup and jQuery libraries.</p>

<pre><code>&lt;?php
    C('#box')-&gt;fadeOut(); 
?&gt;
</code></pre>

<p><strong>_fn()</strong> - Generates a client-side function and returns a reference to the function, which can then be passed to other action script commands. For Example:</p>

<pre><code>&lt;?php
    $cb = _fn('alert("Hello")'); 
    C('body')-&gt;click($cb);
?&gt;
</code></pre>

<p><strong>_var()</strong> - Generates a client-side JavaScript variable and returns a reference to the variable, which can then be passed to other action script commands</p>

<pre><code>&lt;?php
    $v = _var(array(1,2,3,4)); 
    C()-&gt;alert($v);
?&gt;
</code></pre>

<p><strong>_event()</strong> - Generates a client-side function that's used to trigger a server-side event and returns a reference the function, which can be passed to other action script commands.</p>

<pre><code>&lt;?php

    require_once('raxan/pdi/autostart.php');

    class NewPage extends RaxanWebPage {

        protected function _load() {
            if (!$this-&gt;isPostback)
                C()-&gt;confirm("Are you sure you want to continue?",_event('ok'),_event('cancel'));

            // register the 'ok' and 'cancel' page events
            $this-&gt;registerEvent('ok', '.okShow');
            $this-&gt;registerEvent('cancel', '.cancelShow');

        }

        protected function okShow($e){
            $this-&gt;content('Welcome to the Online Demo...');
        }

        protected function cancelShow($e){
            $this-&gt;content('Goodbye!');
        }

    }

?&gt;
</code></pre>

<p>Note: For more information about the above global functions see the <a href="RaxanWebPage.html">RaxanWebPage</a> class reference.</p>

        </div>
        <div class="tpb pad" style="text-align:right">
            <div class="right ltm">
                <a href="table-of-contents.html" title="Back to Table of Content">
                    <img src="images/toc-button.png"  alt="Table of Contents" />
                </a>
            </div>
        </div>
    </div>
</body>

</html>

